﻿using System;
using System.IO;
using System.Xml;

namespace MockingBird.Simulator.Framework
{
    using Common.Infrastructure.Logging;
    using Interfaces;

    public class SimpleSoapResponseBuilder : IResponseBuilder
    {
        private string responseFileName;
        private XmlDocument responseHeader;
        private XmlDocument responseBody;

        private ILogger logger;

        #region "constructor(s)"

        public SimpleSoapResponseBuilder(ILogger logger)
        {
            this.logger = logger;
        }

        #endregion

        #region "public methods"

        public XmlDocument BuildResponse(string bodyDataFile, XmlDocument responseHeader)
        {
            logger.LogInfo("Header will be ignored as this is a simple response builder");

            if (String.IsNullOrEmpty(bodyDataFile))
                throw new ArgumentException("bodyDataFile is null or empty.", "bodyDataFile");

            if (!File.Exists(bodyDataFile))
                throw new FileNotFoundException("File could not be found", bodyDataFile);

            XmlDocument bodyData = new XmlDocument();
            try
            {
                bodyData.Load(bodyDataFile);
            }
            catch (XmlException xex)
            {
                logger.LogError("Xml exception encountered when attempting to load bodyData File :" + bodyDataFile, xex);
                throw;
            }
            return BuildResponse(bodyData, responseHeader);

        }

        public XmlDocument BuildResponse(XmlDocument bodyData, XmlDocument responseHeader)
        {
            logger.LogInfo("SimpleResponseBuilder: headerData is ignored");
            responseBody = bodyData;
            return responseBody;
        }


        #endregion




    }
}
